package com.ysg.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import com.ysg.base.BaseApplication;

public class YChannelUtil {
    private static YChannelUtil instance;

    private YChannelUtil(){
    }

    public static YChannelUtil getInstance(){
        if (instance == null){
            synchronized (YChannelUtil.class){
                if (instance == null){
                    instance = new YChannelUtil();
                }
            }
        }
        return instance;
    }

    public String getChannel() {
        String metaChannel = "";
        try {
            Context context = BaseApplication.getContext();
            ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            if (info == null || info.metaData == null) {
                return metaChannel;
            }
            metaChannel = info.metaData.getString("channel");
        } catch (PackageManager.NameNotFoundException e) {
        }
        return metaChannel;
    }


    public boolean vivo(){
        return YStringUtil.eq("vivo", getChannel());
    }
    public boolean oppo(){
        return YStringUtil.eq("oppo", getChannel());
    }
    public boolean xiaomi(){
        return YStringUtil.eq("xiaomi", getChannel());
    }
    public boolean huawei(){
        return YStringUtil.eq("huawei", getChannel());
    }
    public boolean beta(){
        return YStringUtil.eq("beta", getChannel());
    }

    public String getPlatform(){
        String platform = "android";
        if (huawei()){
            platform = "huawei";
        }else if (xiaomi()){
            platform = "xiaomi";
        }else if (vivo()){
            platform = "vivo";
        }else if (oppo()){
            platform = "oppo";
        }
        return platform;
    }

}
